package utils

import (
	"errors"
	"fmt"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
	"runtime"
	"time"
)

func LoggerInfo(msg string, err string, data zapcore.ObjectMarshaler) {
	defer Logger.Sync()
	_, file, line, _ := runtime.Caller(1)
	if data == nil {
		Logger.Info(msg,
			zap.String("time", FormatTime(time.Now())),
			zap.String("bad", fmt.Sprintf("[bad] in %s[%d:%s]", file, line, err)),
			zap.String("data", ""),
		)
		return
	}
	Logger.Info(msg,
		zap.String("time", FormatTime(time.Now())),
		zap.String("bad", fmt.Sprintf("[bad] in %s[%d:%s]", file, line, err)),
		zap.Object("data", data),
	)
}

func LoggerError(msg string, err string, data zapcore.ObjectMarshaler) {
	_, file, line, _ := runtime.Caller(1)
	defer Logger.Sync()
	if data == nil {
		Logger.Error(msg,
			zap.String("time", FormatTime(time.Now())),
			zap.Error(errors.New(err)),
			zap.String("code", fmt.Sprintf("[error] in %s[%d:%s]", file, line, err)),
			zap.String("data", ""),
		)
		return
	}
	Logger.Error(msg,
		zap.String("time", FormatTime(time.Now())),
		zap.Error(errors.New(err)),
		zap.String("code", fmt.Sprintf("[error] in %s[%d:%s]", file, line, err)),
		zap.Object("data", data),
	)

}
